package com.t282.crm.jedis;

import com.t282.crm.utils.RedisUtil;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import redis.clients.jedis.Jedis;

@SpringBootTest
@RunWith(SpringRunner.class)
public class JedisTester {
    private Jedis jedis;

    @Before
    public void setup(){
        //连接redis服务器；127.0.0.1:6379
        jedis = new Jedis("127.0.0.1",6379);
        //权限认证，指定密码
        //jedis.auth("123");
    }

    @Test
    public void testString(){
        /*添加数据*/
        jedis.set("name","ktjiaoyu");   //插入
        System.out.println(jedis.get("name"));

        jedis.append("name","czkt");    //拼接
        System.out.println(jedis.get("name"));

        /*插入多个*/
        jedis.mset("name","ktjiaoyu","age","17","add","cz");
        jedis.incr("age");  //执行加1操作
        System.out.println(jedis.get("name") + "-" + jedis.get("age") + "-" + jedis.get("add"));
    }

    @Test
    public void testRedisUtil(){
        RedisUtil.set("name","ktjiaoyu");
        System.out.println(RedisUtil.get("name"));

        RedisUtil.del("name");
        System.out.println(RedisUtil.get("name"));
    }
}
